﻿@{
    ViewBag.Title = "核对并提交订单";
    Layout = "~/Areas/Web/Views/Shared/_OrderTopBar.cshtml";
}
<style>
    s { text-decoration: none; }

    .shopa { width: 80px; line-height: 28px; margin: 0; float: left; }

    .shopb { height: 26px; margin: 2px 5px 0 0; border: 1px solid #ccc; line-height: 24px; }

    .shopc { width: 90px; line-height: 28px; margin: 0; float: right; text-align: left; text-align: left; color: #e4393c; }

    .shopd { width: 100px; line-height: 28px; margin: 0; float: right; text-align: right;}

    .shope { width: 180px; line-height: 28px; margin: 0; float: right; text-align: right; margin-right: 20px;}

    .shopf { width: 100px; line-height: 28px; margin: 0; float: right; text-align: right;}

    .shopg { width: 180px; line-height: 28px; margin: 0; float: right; text-align: right; margin-right: 20px;}
</style>
<link href="~/Areas/Web/Content/base.css" rel="stylesheet">
<link href="~/Areas/Web/Content/myjd.easebuy.css" rel="style
sheet">
<div class="w990 m2">
    <div id="checkout">
        <div class="mt">
            <span>填写并核对订单信息</span>
        </div>
        <div id="wizard" class="checkout-steps">
            <div id="step-1" class="step step-complete">
                <div class="step-title">
                    <strong id="consigneeTitleDiv">收货人信息</strong>
                    <span class="step-action"><a href="javascript:;" id="editReciever">[修改]</a></span>
                </div>
                <div class="step-content">
                    <div id="consignee" class="sbox-wrap">
                        <div class="sbox">
                            <div class="s-content">
                                @if (ViewBag.address != null)
                                {
                                    var defaultAddress = (Himall.Model.ShippingAddressInfo)ViewBag.address;
                                    <p id="selectedAddress">@defaultAddress.ShipTo &nbsp;&nbsp;&nbsp; @defaultAddress.Phone &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />@defaultAddress.RegionFullName &nbsp; &nbsp;@defaultAddress.Address&nbsp;</p>
                                }
                                else
                                {
                                    <p id="selectedAddress"></p>
                                }
                            </div>
                            <div class="form" id="addressListArea" style="display:none">
                                <div id="consignee-list">
                                </div>
                                <div class="item" id="use-new-address">
                                    <input type="radio" onclick="showEditArea(0)" class="hookbox" name="address" id="consignee_radio_new" />
                                    <label for="consignee_radio_new">使用新地址 </label><span class="status error" style="display: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当前地址数量已达上限，若要继续添加新地址，请先删除部分收货地址。</span>
                                </div>
                                <form style="display:none" id="addressEditArea">
                                    <div class="consignee-form" id="consignee-form" name="consignee-form">
                                        <div class="list message" id="name_div">
                                            <span class="label"><em>*</em>收货人：</span>
                                            <div class="field">
                                                <input type="text" class="textbox" id="consignee_name" name="shipTo" maxlength="20" onblur="check_Consignee('name_div')" />
                                            </div>
                                            <span class="status error" id="name_div_error"></span>
                                        </div>
                                        <div class="list select-address" id="area_div">
                                            <span class="label"><em>*</em>所在地区：</span>
                                            <div class="field">
                                                <span id="span_area">
                                                    <span id="span_province"><select id="consignee_province"><option value="">请选择：</option></select></span>
                                                    <span id="span_city"><select id="consignee_city"><option value="">请选择：</option></select></span>
                                                    <span id="span_county"><select id="consignee_county"><option value="">请选择：</option></select></span>
                                                    <span id="span_town" style="display:none"><select id="consignee_town"><option value="">请选择：</option></select></span>
                                                </span>
                                            </div>
                                        </div>
                                        <div class="list full-address" id="address_div">
                                            <span class="label"><em>*</em>详细地址：</span>
                                            <div class="field" id="areaName">
                                                <span class="fl selected-address" name="regionFullName"><i>湖南省</i><em>长沙市</em><s>芙蓉区</s></span>
                                                <span class="fl selected-address"></span>
                                                <span class="fl selected-address"></span>
                                                <input type="text" class="textbox" maxlength="50" name="address" />
                                            </div>
                                            <span class="status error" id="address_div_error"></span>
                                        </div>
                                        <div class="list" id="call_div">
                                            <span class="label"><em>*</em>电话：</span>
                                            <div class="field">
                                                <div class="phone">
                                                    <input type="text" class="textbox" name="phone" maxlength="18" />
                                                </div>
                                                <span class="status error" id="call_div_error"></span>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                                <div class="form-btn group">
                                    <a href="javascript:;" class="btn-submit"><span id="saveConsigneeTitleDiv">保存收货人信息</span></a>
                                    <div class="loading loading-1" style="display:none"><b></b>正在提交信息，请等待！</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="step step-complete">
                <div class="step-title"><strong>支付及配送方式</strong></div>
                <div class="step-content">
                    <div id="payment-ship" class="sbox-wrap">
                        <div class="sbox">
                            <div class="payment-selected">
                                <p>在线支付</p>
                                <p>快递运输  由商家选择合作快递为您配送</p>
                            </div>

                        </div>
                    </div>

                </div>
            </div>
            <div class="step step-complete">
                <div class="step-title"><strong>发票信息</strong></div>
                <div class="step-content">
                    <div class="sbox-wrap">
                        <div class="sbox">
                            <div>
                                <span><input type="radio" value="0" id="isInvoce1" name="isInvoce" checked="checked" />不需要发票</span>
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                <span><input type="radio" value="2" id="isInvoce2" name="isInvoce" />需要发票</span>
                            </div>
                            <div class="payment-selected" id="invoceMsg">
                                <span id="" class="mr15">发票抬头：</span><span id="invoiceTitle" class="mr15"></span>
                                <span id="" class="mr15">发票内容：</span><span id="invoiceContext" class="mr15"></span>
                                <a href="#none" class="ftx-05" onclick="invoiceReceipt()">修改</a>
                            </div>
                            <!--<div class="payment-selected">
                                是否需要发票：<input type="checkbox" id="isInvoice" onclick="InvoiceReceipt()" />
                            </div>
                            <div class="payment-selected" id="invoiceReceipt" style="display:none">
                                发票类型：<label><input type="radio" name="invoiceType" value="1">增值税发票</label>
                                <label><input type="radio" name="invoiceType" value="2">普通发票</label>
                                发票抬头：<input type="text" id="invoiceTitle" />
                            </div>-->
                        </div>
                    </div>

                </div>
            </div>
            <div id="step-4" class="step step-complete">
                <div class="step-title"><strong>商品清单</strong></div>
                <div class="step-content">
                    <div id="part-order" class="sbox-wrap">
                        <span class="sbox">
                            <div id="order-cart">
                                @{var products = (List<Himall.Web.Areas.Web.Models.ShopCartItemModel>)ViewBag.products;}
                                <span class="order-review">
                                    @foreach (var p in products)
                                    {
                                        var shop = Himall.Web.Framework.ServiceHelper.Create<Himall.IServices.IShopService>().GetShop(p.shopId);
                                        decimal freefreight = shop == null ? 0 : shop.FreeFreight;
                                        <div class="step-title" style="padding-left:0;"><a target="_blank" href="/shop/home/@p.shopId" class="return-edit" style="float:left;">@p.ShopName</a></div>
                                        <!--商品清单展示-->
                                        <span id="span-skulist">
                                            <table class="review-thead">
                                                <tbody>
                                                    <tr>
                                                        <td class="fore1">商品</td>
                                                        <td class="fore3">服务</td>
                                                        <td class="fore2">单价</td>
                                                        <td class="fore4">数量</td>
                                                        @*<td>运费</td>*@
                                                    </tr>
                                                </tbody>
                                            </table>
                                            <!--**********商品清单内容列表开始************-->



                                            <div class="review-body">
                                                <div class="review-tbody">
                                                    <table class="order-table" shopid="@p.shopId">
                                                        <tbody>
                                                            @{
                                        var service = Himall.Web.Framework.ServiceHelper.Create<Himall.IServices.IProductService>();
                                        var regionService = Himall.Web.Framework.ServiceHelper.Create<Himall.IServices.IRegionService>();
                                        var orderService = Himall.Web.Framework.ServiceHelper.Create<Himall.IServices.IOrderService>();
                                        //杨振国加的保证金标识，这里请重构
                                        var cashDepositService = Himall.Web.Framework.ServiceHelper.Create<Himall.IServices.ICashDepositsService>();
                                        var OrderItems = p.CartItemModels.Select(r =>
                                        {
                                            var skuinfo = service.GetSku(r.skuId);
                                            var product = service.GetProduct(skuinfo.ProductId);
                                            //杨振国加的保证金标识，这里请重构
                                            var cashDeposit = cashDepositService.GetCashDepositsObligation(skuinfo.ProductId);
                                            return new
                                            {
                                                id = r.id,
                                                ProductId = product.Id,
                                                FreightTemplateId = product != null ? product.FreightTemplateId : 0,
                                                price = r.price,
                                                count = r.count,
                                                skuId = r.skuId,
                                                name = r.name,
                                                productCode = r.productCode,
                                                imgUrl = r.imgUrl,
                                                //杨振国加的保证金标识，这里请重构
                                                sevenDayNoReasonReturn=cashDeposit.IsSevenDayNoReasonReturn,
                                                timelyShip=cashDeposit.IsTimelyShip,
                                                customerSecurity=cashDeposit.IsCustomerSecurity
                                                
                                            };
                                        }
                                       );
                                        var freightProductGroup = OrderItems.GroupBy(item => item.FreightTemplateId);
                                                            }
                                                            @foreach (var items in freightProductGroup)
                                                            {
                                                                var productList = items.GroupBy(r => r.ProductId);
                                                                IEnumerable<long> productIds = productList.Select(r => r.Key);
                                                                IEnumerable<int> counts = productList.Select(r => r.Sum(o => o.count));

                                                                int cityId = 0;
                                                                if (ViewBag.address != null)
                                                                {
                                                                    var defaultAddress = (Himall.Model.ShippingAddressInfo)ViewBag.address;
                                                                    string RegionIdPath = defaultAddress.RegionIdPath;
                                                                    cityId = regionService.GetCityId(RegionIdPath);
                                                                }
                                                                decimal freight = freight = cityId <= 0 ? 0 : service.GetFreight(productIds, counts, cityId);
                                                                //decimal freight = freight = 10;
                                                                int rows = 0;
                                                                foreach (var product in items)
                                                                {

                                                                    var skuEntity = orderService.GetSkuByID(product.skuId);
                                                                    string skuStr = string.IsNullOrEmpty(skuEntity.Color) ? "" : "[颜色:" + skuEntity.Color + "]";
                                                                    skuStr += string.IsNullOrEmpty(skuEntity.Size) ? "" : "   [尺码:" + skuEntity.Size + "]";
                                                                    skuStr += string.IsNullOrEmpty(skuEntity.Version) ? "" : "   [规格:" + skuEntity.Version + "]";
                                                                    rows++;
                                                                    <tr skuid="@product.skuId" quntity="@product.count" price="@product.price">
                                                                        <td class="fore1" style="padding:10px;">
                                                                            <div class="p-goods">
                                                                                <div class="p-img"><a href="@Url.Action("Detail", "Product", new { id = product.id })" target="_blank"><img alt="" src="@product.imgUrl" /></a></div>
                                                                                <div class="p-detail">
                                                                                    <div class="p-name">
                                                                                        <a href="@Url.Action("Detail", "Product", new { id = product.id })" target="_blank">@product.name &nbsp; @skuStr<br /> </a>
                                                                                    </div>
                                                                                    <div class="p-more">
                                                                                        商品货号：
                                                                                        <a href="@Url.Action("Detail", "Product", new { id = product.id })" target="_blank">@product.productCode</a>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </td>
                                                                        <td class="fore3">
                                                                        @if (product.customerSecurity)
                                                                        {
                                                                            <img src="/Images/Security.jpg" title="消费者保障" />
                                                                        }
                                                                        @if (product.sevenDayNoReasonReturn)
                                                                        {
                                                                            <img src="/Images/SevenDay.jpg"  title="七天无理由退换货" />
                                                                        }
                                                                        @if (product.timelyShip)
                                                                        {
                                                                            <img src="/Images/TimelyDelivery.jpg" title="及时发货" />
                                                                        }
                                                                        </td>
                                                                        <td class="p-price"><strong>￥@product.price.ToString("F2")</strong></td>
                                                                        <td class="fore2">x @product.count</td>
                                                                        @*@if (rows == 1)
                                                                            {
                                                                                <td class="fore2" rowspan="@items.Count()">
                                                                                    @(freight.ToString("F2"))
                                                                                </td>
                                                                            }*@
                                                                    </tr>
                                                                }
                                                            }
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                            <!--**********商品清单内容列表结束************-->
                                        </span>
                                        <div class="order-summary ordsumbox" data-shopid="@(p.shopId)" id="orderdata_@(p.shopId)" style="background:#eff2f5;">
                                            <div class="statistic fr" style="width:340px;color:#b8c4cc;">
                                                @if (p.UserCoupons.Count > 0 || p.UserBonus.Count  > 0)
                                                {
                                                    <div class="list" style="height:30px;">

                                                        <div class="shopa">店铺优惠：</div>
                                                        <select class="shopb" data-shopid="@(p.shopId)">
                                                            <option value="0" data-type="99" data-p="0">不使用优惠劵</option>
                                                            @*通过属性方式区分优惠方式  如下：
                                                            <option data-type="优惠卷">xx</option><option data-type="红包">xx</option>*@
                                                            @foreach( var c in @p.UserCoupons )
                                                            {
                                                                if( @c.Himall_Coupon.OrderAmount == 0 )
                                                                {
                                                                    <option value="@c.Id" data-p="@c.Himall_Coupon.Price" data-type="0">立减@(c.Himall_Coupon.Price)</option>
                                                                }
                                                                else
                                                                {
                                                                    <option value="@c.Id" data-p="@c.Himall_Coupon.Price" data-type="0">满@(c.Himall_Coupon.OrderAmount)减@(c.Himall_Coupon.Price)</option>
                                                                }
                                                            }
                                                            @foreach( var c in @p.UserBonus )
                                                            {
                                                                if( @c.Himall_ShopBonusGrant.Himall_ShopBonus.UseState == Himall.Model.ShopBonusInfo.UseStateType.None)
                                                                {
                                                            <option value="@c.Id" data-p="@c.Price" data-type="1">立减@(c.Price)</option>
                                                                }
                                                                else
                                                                {
                                                            <option value="@c.Id" data-p="@c.Price" data-type="1">满@(c.Himall_ShopBonusGrant.Himall_ShopBonus.UsrStatePrice)减@(c.Price)</option>
                                                                }
                                                            }
                                                        </select>
                                                        <div class="shopc" data="0">-0</div>
                                                    </div>
                                                }
                                                <div class="list" style="height:60px;">
                                                    <div class="shopd" data="@((p.CartItemModels.Sum(item => item.price * item.count) + p.Freight).ToString("F2"))" data-v="@((p.CartItemModels.Sum(item => item.price * item.count)).ToString("F2"))" style="width:140px;text-align:center;">￥@((p.CartItemModels.Sum(item => item.price * item.count) + p.Freight).ToString("F2"))</div>
                                                    <div class="shope">店铺合计（含运费）：</div>

                                                    <div class="span clr"></div>
                                                    <div class="shopf" data="@p.Freight" data-profrei="@p.Freight" data-free="@(freefreight)" style="width:140px;text-align:center;">￥@p.Freight</div>
                                                    <div class="shopg">@(freefreight > 0 ? "（满" + freefreight.ToString("F2") +"免运费）": "")运费：</div>

                                                </div>
                                            </div>
                                            <div class="span clr"></div>
                                        </div>
                                    }
                                    <div class="order-summary" style="padding-top:30px;">
                                        <div class="statistic fr">
                                            <div class="list">
                                                <span><em id="span-skuNum">@products.Sum(item => item.CartItemModels.Sum(a => a.count))</em> 件商品，总商品金额：</span>
                                                <em class="price" id="warePriceId" v="@ViewBag.totalAmount">￥@ViewBag.totalAmount.ToString("F2")</em>
                                            </div>
                                            <div class="list"><span>运费：</span><em class="price" id="totalFreight"> ￥@ViewBag.Freight.ToString("F2")</em></div>
                                            <div class="list" style="display:none"><span>优惠券抵扣金额：</span><em class="price" id="id_c"></em></div>

                                            @if (ViewBag.IntegralPerMoney != 0 && ViewBag.Integral != 0)
                                            {
                                                <div>
                                                    <span style="line-height:30px;">
                                                        <input type="checkbox" id="IsUsedIntegral" /> 使用平台积分
                                                        <label class=""><input type="text" style="width:40px;" onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v()" class="quantity-text" data-userintegral="@ViewBag.Integral" data-rule="@ViewBag.IntegralPerMoney" name="integral" id="integral" value="0" /> 分：</label><em style="display: inline-block;float: right;position: relative;width: 500px;color: #7b8b94;">可用 @ViewBag.Integral 积分</em>
                                                    </span>
                                                    <em class="price" id="integralPrice"> ¥0.00</em>
                                                </div>
                                            }
                                        </div>
                                        <div class="span clr"></div>
                                    </div>

                            </div>
                        </span>
                        <span class="clr"></span>
                    </div>

                    <div class="checkout-buttons group">
                        <div class="sticky-placeholder">
                            <div class="sticky-wrap">
                                <div class="inner">
                                    <span class="total" style="float:left;padding-left:20px;"><a href="/cart/cart" class="return-edit">返回修改购物车</a></span>
                                    <button type="button" id="submit" class="checkout-submit">提交订单<b></b></button>
                                    <span class="total">应付总额：<strong id="payPriceId" data-real="@ViewBag.orderAmount.ToString("F2")" data="@ViewBag.orderAmount.ToString("F2")">@ViewBag.orderAmount.ToString("F2")</strong>元</span>
                                    @if (ViewBag.MoneyPerIntegral > 0)
                                    {
                                        <span style="  float: right;line-height: 50px;margin-right: 20px;color:#7b8b94;">可获得平台积分<span id="MoneyPerIntegral" data-rule="@ViewBag.MoneyPerIntegral">@ViewBag.TotalIntegral</span>分</span>
                                    }
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="thickdiv hide"></div>
<div class="thickbox hide" id="invoiceDialog">
    <div class="thickwrap">
        <div class="thicktitle"><span>发票信息</span></div>
        <div style="width: 450px; padding:10px;" class="thickcon">
            <div id="edit-cont" class="m">
                <div class="mc">
                    <div class="form" id="dvInvoice">
                        <div class="item mt15">
                            <span class="label fl">发票抬头：</span>
                            <div class="fl invoice-tit-list">
                                @foreach (var item in (List<Himall.Model.InvoiceTitleInfo>)ViewBag.InvoiceTitle)
                                {
                                    <div class="invoice-item">
                                        <input type="text" value="@item.Name" disabled>
                                        <div class="item-btns">
                                            <a href="javascript:void(0);" class="ml10 del-tit" key="@item.Id">删除</a>
                                        </div>
                                    </div>
                                }
                                <div class="invoice-item invoice-item-selected">
                                    <input type="text" value="个人" disabled>
                                </div>
                                <a id="btnAddInvoice" class="addInvoice" href="javascript:;">新增单位发票</a>
                            </div>
                        </div>
                        <div class="item mt15">
                            <span class="label fl">发票内容：</span>
                            <div class="fl invoice-list">
                                @foreach (var item in (List<Himall.Model.InvoiceContextInfo>)ViewBag.InvoiceContext)
                                {
                                    <div class="invoice-item"><span>@item.Name</span></div>
                                }
                            </div>
                            <div class="clr"></div>
                        </div>
                        <div class="btns" style="padding-left: 60px">
                            <a id="btnOk" class="e-btn btn-5 save-btn" href="javascript:;">确定</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <a id="" class="thickclose" href="#">×</a>
    </div>
</div>
<input type="hidden" id="collIds" value="@ViewBag.collIds">
<input type="hidden" id="skuIds" value="@ViewBag.skuIds">
<input type="hidden" id="counts" value="@ViewBag.counts">
<input type="hidden" id="shippingAddressId" value="@(ViewBag.address != null ? ((Himall.Model.ShippingAddressInfo)ViewBag.address).Id.ToString() : "")" />
<input type="hidden" id="cartItemIds" value="@ViewBag.cartItemIds" />

<script src="~/Scripts/Region.js"></script>
<script src="~/Scripts/regionBind.js"></script>
<script src="~/Areas/Web/Scripts/submitOrder.js"></script>
<script src="~/Scripts/CommonJS.js"></script>
<script>
    function invoiceReceipt() {
        var left, top, width, height;
        left = $(window).width() / 2;
        top = $(window).height() / 2;
        width = $('.thickbox').width() / 2;
        height = $('.thickbox').height() / 2;
        $('.thickdiv').show();
        $('#invoiceDialog').css({ top: '50%', left: '50%', marginLeft: '-' + width + 'px', marginTop: '-' + height + 'px', position: 'fixed' }).show();
    }
    //转换0
    function parseFloatOrZero(n) {
        result = 0;
        try {
            if (n.length < 1) n = 0;
            if (isNaN(n)) n = 0;
            result = parseFloat(n);
        } catch (ex) {
            result = 0;
        }
        return result;
    }

    //显示实付金额
    //By DZY[150706]
    function ShowPaidPrice() {
        var d_mpi = $('#MoneyPerIntegral');
        var d_integral = $("#integral");
        //价格初始
        var orderTotalPrice = parseFloatOrZero($("#warePriceId").attr("v"));  //订单总价
        var orderPaidPrice = 0;
        var orderTotalDisPrice = 0;       //订单优惠总价
        var orderTotalFreight = 0;        //订单运费总价
        var orderTotalIntegral = 0;       //订单积分抵扣
        //运费总价
        $(".shopf").each(function (l, k) {
            var _t = $(k);
            orderTotalFreight += parseFloatOrZero(_t.attr("data"));
        });
        //总优惠
        $(".shopc").each(function (l, k) {
            var _t = $(k);
            orderTotalDisPrice += parseFloatOrZero(_t.attr("data"));
        });
        //积分抵扣
        var intRule = parseFloatOrZero(d_integral.data('rule'));   //积分规则
        if (intRule > 0) {
            var useIntegral = parseFloatOrZero(d_integral.val());
            if (useIntegral < 0) {
                useIntegral = 0;
                d_integral.val(useIntegral);
            }
            var canuseint = parseFloatOrZero(d_integral.data("userintegral"));
            if (canuseint < useIntegral) useIntegral = canuseint;
            orderTotalIntegral = (useIntegral / intRule).toFixed(2);
            var _tmpnum = parseInt((orderTotalPrice - orderTotalDisPrice)*100)/100;
            if (_tmpnum - orderTotalIntegral < 0) {
                //为零修正
                orderTotalIntegral = _tmpnum;
                useIntegral = Math.floor(orderTotalIntegral * intRule);
                //无法抵价
                if (useIntegral > 0) {
                    orderTotalIntegral = (useIntegral / intRule).toFixed(2);
                } else {
                    orderTotalIntegral = 0;
                    d_integral.val(0);
                }
            }
            //数据补充
            if (useIntegral != 0) {
                d_integral.val(useIntegral);
            } else {
                if (d_integral.val().length > 1) {
                    d_integral.val(0);
                }
            }
        } else {
            d_integral.val(0);
        }

        //计算实付
        orderPaidPrice = orderTotalPrice + orderTotalFreight - orderTotalDisPrice - orderTotalIntegral;

        //显示
        var d_ordprice = $("#payPriceId");
        var d_ordFreight = $("#totalFreight");
        var d_ordDisPrice = $("#id_c");
        var d_ordMPI = $("#MoneyPerIntegral");
        var d_orduseInt = $("#integralPrice");
        d_ordprice.attr("v", orderPaidPrice.toFixed(2)).html("￥" + orderPaidPrice.toFixed(2));
        d_ordFreight.html("￥" + orderTotalFreight.toFixed(2));
        d_ordDisPrice.html("-￥" + orderTotalDisPrice.toFixed(2));
        d_orduseInt.html("-￥" + orderTotalIntegral);
        d_ordDisPrice.parent().hide();
        if (orderTotalDisPrice > 0) {
            d_ordDisPrice.parent().show();
        }
        //可获得积分
        var mpirule = parseFloatOrZero(d_ordMPI.data("rule"));
        if ((orderPaidPrice - orderTotalFreight > 0) && mpirule>0) {
            d_ordMPI.text(Math.floor((orderPaidPrice - orderTotalFreight) / mpirule));
        }
        else {
            d_ordMPI.text(0);
        }
    }

    //计算订单结果
    //By DZY[150707]
    function ComputeOrder(shopid) {
        var d_box = $("#orderdata_" + shopid);
        var d_dissel = d_box.find(".shopb");
        var d_freight = d_box.find(".shopf");
        var d_proPrice = d_box.find(".shopd");
        var d_showdis = d_box.find(".shopc");
        var ordSumProPrice = 0, ordSubDisPrice = 0; ordSubFreight = 0, shopFreeFrei = 0;
        ordSumProPrice = parseFloatOrZero(d_proPrice.data("v"));
        shopFreeFrei = parseFloatOrZero(d_freight.data("free"));
        ordSubFreight = parseFloatOrZero(d_freight.data("profrei"));
        if (d_dissel.length > 0) {
            var d_selopt = d_dissel.find("option:selected");
            ordSubDisPrice = parseFloatOrZero(d_selopt.data("p"));
        }
        //计算满额免
        var isFullFreeFrei = false;
        if (shopFreeFrei > 0) {
            if (ordSumProPrice - ordSubDisPrice >= shopFreeFrei) {
                ordSubFreight = 0;
                isFullFreeFrei = true;
            }
        }

        //计算实付
        var ordPaidPrice = ordSumProPrice - ordSubDisPrice + ordSubFreight;

        //显示单条
        d_proPrice.html("￥" + ordPaidPrice);
        d_freight.html("￥" + ordSubFreight).attr("data", ordSubFreight);
        if (isFullFreeFrei) {
            d_freight.html("免运费");
        }
        d_showdis.html("-￥" + ordSubDisPrice).attr("data", ordSubDisPrice);
        //d_showdis.hide();
        if (ordSubDisPrice == 0) {
            d_showdis.html("");
        }
        //显示计算结果
        ShowPaidPrice();
    }

    $(function () {

        $(document).on('click', '.thickclose', function () {
            $('.thickbox,.thickdiv').hide();
        });


        var freight = '@ViewBag.Freight.ToString("F2")';
        var intRule = $('#MoneyPerIntegral').data('rule');

        $("#integral").bind("keyup", function () {
            ShowPaidPrice();
            //var IntegralPerMoney = $(this).data("rule");
            //var inputIntegral = parseInt($(this).val() | 0);
            //var userIntegral = $(this).data("userintegral");
            //if (inputIntegral <= 0) {
            //    inputIntegral = 0;
            //    $(this).val(0);
            //}
            //if (inputIntegral > userIntegral) {
            //    inputIntegral = userIntegral;
            //    $(this).val(userIntegral);
            //}
            //var result = (inputIntegral / IntegralPerMoney).toFixed(2);
            //var payMoney = $("#warePriceId").attr("v") - price();
            //if (payMoney - result <= 0) {
            //    var integral = parseInt(IntegralPerMoney * payMoney);
            //    $(this).val(integral);
            //    result = payMoney;
            //}

            //$("#integralPrice").text('-￥' + result);
            //$('#payPriceId').text(($('#payPriceId').data('real') - result).toFixed(2));
            //if ($('#payPriceId').text() - freight > 0) {
            //    $('#MoneyPerIntegral').text(Math.floor(($('#payPriceId').text() - freight) / intRule));
            //}
            //else {
            //    $('#MoneyPerIntegral').text(0);
            //}
        });

        $("#IsUsedIntegral").change(function () {
            if (this.checked) {
                $(this).siblings().show().end().parent().siblings().show();
            } else {
                $(this).siblings().hide().end().parent().siblings().hide();
                $('#integral').val(0);
                $("#integral").trigger("keyup");
            }
        });

        $("#MoneyPerIntegral").html();

        var price = function () {
            var a = 0;
            $('.shopb').each(function (i, e) {
                $(e).children().each(function (l, k) {
                    if ($(k).attr('selected')) {
                        var b = $(k).attr('data-p');
                        a += (b | 0);
                    }
                });
            });
            return a;
        },
        total = $('#payPriceId').attr('data');

        //优惠切换绑定
        $('.shopb').bind('change', function (t) {
            var _t = $(this);
            var shopid = _t.data("shopid");
            ComputeOrder(shopid);
        });

        //下面两个调用需同步执行
        //优惠初始
        $('.shopb').each(function (i, e) {
                var _t = $(e);
                _t.find("option").eq(1).attr("selected", true);
        });

        //初始计算
        $(".ordsumbox").each(function (i, e) {
                var _t = $(e);
                var shopid = _t.data("shopid")
                ComputeOrder(shopid);
        });

    });
</script>
